package com.xqboss.apps.vo.nft;

import com.alibaba.fastjson2.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.xqboss.apps.domain.marketing.ThemePage;
import com.xqboss.apps.domain.marketing.vo.MarketingRightsCardVO;
import com.xqboss.apps.domain.nft.ChainSeries;
import com.xqboss.apps.domain.nft.NftAttr;
import com.xqboss.apps.domain.nft.NftCategory;
import com.xqboss.apps.domain.nft.PrizeGift;
import com.xqboss.apps.dto.nft.ChainLevelDTO;
import com.xqboss.apps.dto.nft.ChainSeriesDTO;
import com.xqboss.apps.dto.nft.NftExclusiveBuyDTO;
import com.xqboss.apps.util.mh.CommonUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Getter
@Setter
public class NftOldVO {

    private Long id;

    @ApiModelProperty(value = "作品名称")
    @NotBlank(message = "作品名称不能为空")
    private String title;


    @ApiModelProperty("编号")
    private String selfCode;

    @ApiModelProperty(value = "描述")
    @Max(value = 1000, message = "描述最大值为300个汉字")
    private String description;

    @ApiModelProperty(value = "主图")
    @NotBlank(message = "主图不能为空")
    private String mainImg;

    @ApiModelProperty(value = "展示图集")
    @NotBlank(message = "展示图集不能为空")
    private List<String> displayImgs;

    public void setDetailImgs(String detailImgs) {
        if (detailImgs == null || detailImgs.isEmpty()) {
            this.detailImgs = new ArrayList<>();
            return;
        }
        this.detailImgs = CommonUtil.stringToStringList(detailImgs, ",");
    }

    public void setDisplayImgs(String displayImgs) {
        if (displayImgs == null || displayImgs.isEmpty()) {
            this.displayImgs = new ArrayList<>();
            return;
        }
        this.displayImgs = CommonUtil.stringToStringList(displayImgs, ",");
        ;
    }

    @ApiModelProperty(value = "作者ID")
    @NotNull(message = "作者ID不能为空")
    @Positive(message = "作者ID必须是正整数")
    private Integer authorId;

    @ApiModelProperty(value = "作者名称")
    @NotBlank(message = "作者名称不能为空")
    private String authorName;

    @ApiModelProperty(value = "作者头像")
    private String authorHeadimg;


    @ApiModelProperty(value = "发行方ID")
    @NotNull(message = "发行方ID不能为空")
    @Positive(message = "发行方ID必须是正整数")
    private Integer publishId;

    @ApiModelProperty(value = "发行方名称")
    @NotBlank(message = "发行方名称不能为空")
    private String publishName;

    @ApiModelProperty(value = "发行方头像")
    private String publishHeadimg;

    @ApiModelProperty(value = "作品详情")
    @NotBlank(message = "作品详情不能为空")
    private List<String> detailImgs;

    @ApiModelProperty(value = "发行价格")
    @NotNull(message = "发行价格不能为空")
    @DecimalMin(value = "0.01", message = "发行价格最小值为0.01")
    private BigDecimal price;

    @ApiModelProperty(value = "发行数量")
    @NotNull(message = "发行数量不能为空")
    @Positive(message = "发行数量必须是正整数")
    private Integer stock;

    @ApiModelProperty(value = "每人限购")
    @NotNull(message = "每人限购不能为空")
    @Min(value = 0, message = "每人限购最小值为0")
    private Integer limitStock;

    @ApiModelProperty(value = "发售时间")
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @NotNull(message = "发售时间不能为空")
    private Date publishTime;

//    public void setPublishTime(String publishTime) {
//        System.out.println(publishTime);
////        this.publishTime = publishTime;
//    }

    @ApiModelProperty(value = "排序")
    @NotNull(message = "排序不能为空")
    private Integer sort = 0;

    @ApiModelProperty(value = "标签数据")
    @NotBlank(message = "标签数据不能为空")
    private String tags;


    @ApiModelProperty(value = "分类数据")
    private List<List<NftCategory>> categories;

    @ApiModelProperty(value = "是否上下架")
    private Integer isOnline;

    @ApiModelProperty(value = "销量")
    private Integer saledNum;

    @ApiModelProperty(value = "是否开启转卖")
    private Boolean openSell;

    @ApiModelProperty(value = "转卖封闭期 单位天")
    private BigDecimal sellCloseDay;


    @ApiModelProperty(value = "是否开启转赠")
    private Boolean openSend;

    @ApiModelProperty(value = "转赠封闭期 单位天")
    private BigDecimal sendCloseDay;

    @ApiModelProperty(value = "作品类型 1图片 2模型")
    private Integer showType;

    @ApiModelProperty(value = "模型压缩包名称")
    private String zipName;

    @ApiModelProperty(value = "是否可购买")
    private Integer canBuy;

    @ApiModelProperty("权益卡")
    private MarketingRightsCardVO marketingRightsCard;


    @ApiModelProperty(value = "是否赠送礼品 0:否 1:是")
    private Integer isGiveGift;

    @ApiModelProperty(value = "绑定权益卡Id")
    private Integer rightsCardId;

    @ApiModelProperty(value = "赠品类型 1:权益卡 2:藏品")
    private Integer giftType;

    @ApiModelProperty(value = "绑定赠品Id")
    private Long giftId;

    @ApiModelProperty(value = "是否开启优先购 1:是 0:否")
    private Integer isPriorityBuy;

    @ApiModelProperty(value = "优先购最大购买次数")
    private Integer priorityTimes;

    @ApiModelProperty("优先购提前购买天数")
    private Integer priorityDate;

    @ApiModelProperty("分销设置,1默认,2自定义")
    private Integer distribution;

    @ApiModelProperty("买家上级自定义分销比例,单位百分号")
    private BigDecimal distributionProportion;


    @ApiModelProperty("生成编号是否随机,0不随机,1随机")
    private Integer numRandom;

    @ApiModelProperty("活动库存用于盲盒 合成等营销活动")
    private Integer extraStock;

    @ApiModelProperty("身份限购 0 关闭 1开启")
    private Integer limitUser;
    @ApiModelProperty("商城新人限购开启时间")
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date limitStart;
    @ApiModelProperty("商城新人限购结束时间")
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date limitEnd;
    @ApiModelProperty("剩余库存")
    private Integer surplusStock;

    @ApiModelProperty("首发初始库存")
    private Integer firstStock;

    @ApiModelProperty("活动初始库存")
    private Integer firstExtraStock;

    @ApiModelProperty(value = "显示库存")
    private Integer displayStock;

    public Integer getFirstExtraStock() {
        return initialStock - firstStock;
    }

    @ApiModelProperty(value = "初始库存")
    private Integer initialStock;

    @ApiModelProperty("下架冷却状态,1默认,2自定义,3关闭")
    private Integer lowerShelfCooling;

    @ApiModelProperty("冷却时间,单位为小时")
    private BigDecimal shelfTime;


    @ApiModelProperty("是否上链,1上链,0不上链")
    private Integer blockChain;


    @ApiModelProperty("开启专属购 0关闭 1 开启")
    private Integer openExclusiveBuy;

    @ApiModelProperty("专属购数据")
    private List<NftExclusiveBuyDTO> nftExclusiveBuyDTOS;

    @ApiModelProperty("集市状态false:关闭,true:开启")
    private Boolean marketStatus;

    @ApiModelProperty("集市费率,百分比")
    private BigDecimal serviceRate;

    @ApiModelProperty("定时维护状态false:关闭,true:开启")
    private Boolean marketMaintainStatus;

    @ApiModelProperty("定时维护起始时间,格式:HH:mm:ss")
    private String marketMaintainStart;

    @ApiModelProperty("定时维护结束时间,也是开放时间(结束时间不包含,开放时间包含),格式:HH:mm:ss")
    private String marketMaintainEnd;

    @ApiModelProperty("转卖限价状态0:默认,1:开启,2自定义")
    private Integer resellFixedPriceStatus;

    @ApiModelProperty("限价依据,0基准值,1固定值")
    private Integer fixedPriceBasis;

    @ApiModelProperty("计算公式,0交易均价,1交易峰值,2交易底值")
    private Integer calculationFormula;

    @ApiModelProperty("最低限价,如果是基准值,则这里单位是百分比,如果是固定值,则这里单位是元")
    private BigDecimal minFixedPrice;

    @ApiModelProperty("最高限价,如果是基准值,则这里单位是百分比,如果是固定值,则这里单位是元")
    private BigDecimal maxFixedPrice;

    @ApiModelProperty("是否数据清理false:不清理,true:清理,将不符合的下架")
    private Boolean dataClear;

    @ApiModelProperty("转卖封禁状态false:关闭,true:开启")
    private Boolean resellInterdiction;

    @ApiModelProperty("每日免封次数")
    private Integer dayExemptFrequency;

    @ApiModelProperty("首次获得封禁时间,单位为小时")
    private BigDecimal firstGetInterdiction;

    @ApiModelProperty("集市获得封禁时间,单位为小时")
    private BigDecimal marketGetInterdiction;

    @ApiModelProperty("转卖封禁，0默认，1自定义")
    private Integer sellForbidden;

    @ApiModelProperty(value = "自定义转赠封闭期 单位小时")
    private BigDecimal sendCloseTime;


    @ApiModelProperty(value = "发售截止时间")
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date publishEndTime;

    @ApiModelProperty("是否开启持图购 0 关闭 1 开启")
    private Integer isOpen;

    @ApiModelProperty(value = "持图购限购数量")
    private Integer holdLimitStock;

    @ApiModelProperty(value = "防刷单 1开启 0关闭")
    private Integer limitBrush;

    @ApiModelProperty(value = "次数计算方式 1求和 2最大 3最小")
    private Integer timesMode;

    @ApiModelProperty(value = "开启优惠 1开启 0关闭")
    private Integer openDiscount;

    @ApiModelProperty(value = "折扣模式 1比例 2固定值")
    private Integer discountMode;

    @ApiModelProperty(value = "持图购数据")
    private List<HoldPictureVO> holdPictures;


    @ApiModelProperty("分库库存相关信息")
    private NftRepertorySeparationVo nftRepertorySeparationVo;

    @ApiModelProperty(value = "是否分库， 1分库 2不分库")
    private Integer branchWarehouse;


    @ApiModelProperty(value = "商品流通总量")
    private Integer num;

    @ApiModelProperty(value = "商品流通总量，在前台是否显示，1显示，0不显示")
    private Integer isShow;

    @ApiModelProperty(value = "藏品编号")
    private String nftNumber;

    @ApiModelProperty(value = "等级ID")
    private Integer levelId;

    @ApiModelProperty(value = "等级名称")
    private String levelName;

    public String getLevelName() {
        if (levelId != null && levelId != 0) {
            return ChainSeries.ChainLevelEnum.toLevel(levelId).getLevelName();
        }
        return "";
    }

    @ApiModelProperty(value = "是否绑定")
    private Integer isBind;

    @ApiModelProperty(value = "属性数据")
    private List<NftAttr> nftAttrs;

    private Integer holdCount;

    private Integer circulationNum;

    @ApiModelProperty("是否开启特权")
    private Boolean openPrivilege;

    private String displayPngImgs;

    @ApiModelProperty(value = "组件图")
    private String unitImgs;

    @ApiModelProperty(value = "组件图")
    private List<String> unitImgList;


    @ApiModelProperty(value = "是否开启兑换时效")
    private Integer exchangeTimeOpen = 0;

    @ApiModelProperty(value = "兑换时限")
    private BigDecimal exchangeTime = new BigDecimal(0);

    @ApiModelProperty(value = "礼包内容")
    private List<PrizeGift> prizeGiftList = new ArrayList<>();

//    public void setUnitImgs(String unitImgs) {
//        if (!unitImgs.isEmpty()){
//            this.unitImgs = JSONObject.parseArray(unitImgs,String.class);
//        }
//    }
//

    public List<String> getUnitImgList() {
        if (!unitImgs.isEmpty()) {
//            return JSONObject.parseArray(unitImgs, String.class);
        }
        return unitImgList;
    }
//    public List<String> getUnitImgs() {
//        return unitImgs;
//    }

    @ApiModelProperty(value = "藏品类型 1普通藏品 2宠物藏品 3道具藏品")
    private Integer nftType = 1;

    @ApiModelProperty(value = "藏品持有总人数")
    private Integer numberOfHolders;

    @ApiModelProperty(value = "在售数量")
    private Integer salesNum;

    private List<ThemePage> pages;

    @ApiModelProperty(value = "铸造器数据")
    private ChainSeriesDTO chainSeriesDTO;


    @ApiModelProperty(value = "是否显示等级")
    private Integer displayLevel;

    @ApiModelProperty(value = "系列ID")
    private Long chainSeriesId;

    @ApiModelProperty(value = "限定方式 0不限制1等级2宠物藏品")
    private Integer limitType = 0;

    @ApiModelProperty(value = "限定规则详情")
    private List<Long> limitRule;

    @ApiModelProperty(value = "限定等级")
    List<ChainLevelDTO> limitLevels = new ArrayList<>();

    @ApiModelProperty(value = "限定藏品")
    List<NftOldVO> limitNfts = new ArrayList<>();

    @ApiModelProperty(value = "限定槽位 1玉珠 2天珠 3灵珠")
    private List<Integer> limitSlotPositions;

    @ApiModelProperty("礼包积分")
    private List<PrizeGift> integral = new ArrayList<>();

    @ApiModelProperty(value = "种族 0其他 蟾蜍: 1巨龙2魔龙 3圣龙 / 五行圣兽: 4金 5木 6水 7火 8土")
    private Integer raceId;

    @ApiModelProperty(value = "派系 1蟾蜍 2五行圣兽")
    private Integer factionsId;

    @ApiModelProperty(value = "合成冷却是否开启 1开启 0关闭")
    private Integer compoundCoolingShow;

    @ApiModelProperty(value = "合成冷却是否开启 1开启 0关闭")
    private Integer compoundCoolingTime;

    @ApiModelProperty(value = "主图显示：0.组件图，1.详情图集")
    private Integer mainImageDisplay;

    @ApiModelProperty(value = "是否推荐 0不推荐 1推荐")
    private Integer Recommend;

    @ApiModelProperty(value = "补充类型 0其他 1精力 2生命值 3孵化器耐久度（麦盒 聚气丹）")
    private Integer supplementaryType;

    @ApiModelProperty(value = "藏品历史价格")
    private Map<String, BigDecimal> historicalPrices;
    @ApiModelProperty(value = "市场价格")
    private BigDecimal mallMarketPrice;
    @ApiModelProperty(value = "运费")
    private BigDecimal deliveryFee;
    @ApiModelProperty(value = "是否开启抵扣")
    private Integer mallIsOpen;
    @ApiModelProperty(value = "玉珠抵扣金额")
    private BigDecimal integralCashAmount;
    @ApiModelProperty(value = "天珠抵扣金额")
    private BigDecimal jindouCashAmount;
    @ApiModelProperty(value = "灵珠抵扣金额")
    private BigDecimal energyCashAmount;
    @ApiModelProperty(value = "代币4抵扣金额")
    private BigDecimal coinCashAmount;
    @ApiModelProperty(value = "淘宝价格")
    private BigDecimal taoBao;
    @ApiModelProperty(value = "是否开启满减活动 1开启 0不开启")
    private Integer isFullReduce;
    @ApiModelProperty(value = "发行方备注")
    private String remarks;

    public void setLimitRule(String limitRule) {
        if (limitRule == null || limitRule.isEmpty()) {
            this.limitRule = new ArrayList<>();
        }
        this.limitRule = JSON.parseArray(limitRule, Long.class);
    }
}
